package thread;

import java.util.Scanner;

public class Demo21 {
    private volatile static int flag=0;
    //volatile,线程t1进入循环速度非常快，以至于不会继续在内存读取flag，把他搞在寄存器
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            while (flag==0){

            }
            System.out.println("线程一结束");
        });
        Thread t2=new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            System.out.println("请输入flag的值");
            flag=scanner.nextInt();
        });
        t1.start();
        t2.start();
    }
}
